<template>
  <div>
    <el-form>
      <el-form-item>
        <el-button type="primary" icon="el-icon-plus" @click="pointAdd()">新增</el-button>
      </el-form-item>
      <el-table
        :data="tableData"
        border>
        <el-table-column label="序号" type="index" width="80" align="center"/>
        <el-table-column label="名称" prop="name" align="center"/>
        <el-table-column label="简介" prop="brief" align="center"/>
        <el-table-column label="排序" prop="sort" align="center"/>
        <el-table-column label="更新时间" prop="updateTime" align="center"/>
        <el-table-column header-align="center" align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="pointAdd(scope.row.id)">编辑</el-button>
            <el-button type="text" @click="pointDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
    <pointadd ref="pointadd" @refreshDataList="getList"/>
  </div>
</template>

<script>
  import Pointadd from './pointadd'

  export default {
    name: 'pointsrule',
    components: {Pointadd},
    data() {
      return {
        tableData: []
      }
    },
    mounted() {
      this.getList()
    },
    methods: {
      getList() {
        this.$http({
          url: this.$http.adornUrl('/integral-admin/rule/app/list'),
          method: 'post'
        }).then(res => {
          this.tableData = res.data
        })
      },
      pointAdd(id) {
        this.$nextTick(() => {
          this.$refs.pointadd.init(id)
        })
      },
      pointDelete(id) {
        this.$confirm(`确定要进行删除操作吗？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/integral-admin/rule/app/delete'),
            method: 'post',
            data: {id: id}
          }).then(res => {
            if (res && res.code === 200) {
              this.getList()
              this.$notify({
                title: '成功',
                message: '删除成功',
                type: 'success'
              })
            } else {
              this.$notify.error({
                title: '提示',
                message: res.msg
              })
            }
          })
        })
      }
    }
  }
</script>

<style scoped>

</style>
